#include<bits/stdc++.h>
using namespace std;
int arr[100010];
int dp[100010][2];
int main() {
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		for (int i = 1; i <= n; i++)cin >> arr[i];
		int sum = 0;
		for (int i = 2; i * 2 <= n; i++)
		{
			if (arr[i] == arr[i - 1] || arr[n - i + 1] == arr[n - i + 2])
			{
				swap(arr[i], arr[n - i + 1]);
			}
		}
		for (int i = 2; i <= n; i++)
			if (arr[i] == arr[i - 1])sum++;
		cout << sum << endl;
	}

	
}